package com.ldd.malphite.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericToStringSerializer;

/**
 * @Configuration(proxyBeanMethods = true)
 * proxyBeanMethods = false,如果注册的Bean之间没有依赖关系，可以设置成false，提高springboot项目的启动速度
 */

@Configuration
//@Import({Car.class})  //给容器中自动创建引入的组件（自动调用要调用组件的无参构造方法）,组件名字默认为全类名
//@ImportResource() 引入原生的spring  配置文件
public class ConfigurationCenter {


    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new GenericToStringSerializer<>(String.class));
        redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Object.class));
        return redisTemplate;
    }
}
